<?php

namespace App\Api;

use PhalApi\Api;


/**
 * 万国觉醒 imei帐号数量
 *
 * @author: dogstar <chanzonghuang@gmail.com> 2014-10-04
 */
class RokImeiCount extends Api
{

    public function getRules()
    {
        return array(
            'index' => array(),
        );
    }

    /**
     * rok-token
     * @desc 多条件查询接口
     * @return array data 被查数据
     * @exception 400 非法请求，参数传递错误
     */
    public function index()
    {
        header('Access-Control-Allow-Origin:*');
        $imei = \PhalApi\DI()->notorm
            ->rok_imei
            ->fetchAll();

        if ($imei) {
            foreach ( $imei as $key=>$value ){
                $imei_id = $value['id'];
                $count = \PhalApi\DI()->notorm->rok_account
                    ->where('imei_id',$imei_id)
                    ->count("id");
                \PhalApi\DI()->notorm->rok_imei
                    ->where('id',$imei_id)
                    ->update(
                        array(
                            'count' => $count
                        )
                    );
            }
        }
        return '';
    }


}
